package com.lxp.jx.ui.home;

import android.net.Uri;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.lxp.jx.R;
import com.lxp.jx.adapter.HomeAdapter;
import com.lxp.jx.constant.IntentTypeConstants;
import com.lxp.jx.listener.OnFragmentInteractionListener;
import com.lxp.jx.ui.test.TestActivity;
import com.yonyou.integration.base.BaseActivity;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

public class MainActivity extends BaseActivity implements OnFragmentInteractionListener {

    @BindView(R.id.vp_home)
    ViewPager vpHome;
    @BindView(R.id.activity_main)
    LinearLayout activityMain;
    @BindView(R.id.tabl_home)
    TabLayout tablHome;
    @BindView(R.id.toolbar)
    Toolbar toolbar;
    @BindView(R.id.tv_tests)
    TextView tv_tests;


    private PoetryFragment mPoetryFragment;
    private ArticleFragment mArticleFragment;
    private HomeAdapter mAdapter;
    private List<Fragment> mFragmentList = new ArrayList<>();

    private List<String> mTabList = new ArrayList<>();

    @Override
    public void widgetClick(View v) {

    }

    @Override
    public void initParms(Bundle parms) {

    }

    @Override
    public View bindView() {
        return null;
    }

    @Override
    public int bindLayout() {
        return R.layout.activity_main;
    }

    @Override
    public void initView(View view) {

        tv_tests.setText("13123123123123");
        mTabList.add("诗");
        mTabList.add("文");

        mPoetryFragment = PoetryFragment.newInstance("", "");
        mArticleFragment = ArticleFragment.newInstance("", "");
        mFragmentList.add(mArticleFragment);
        mFragmentList.add(mPoetryFragment);


        mAdapter = new HomeAdapter(getSupportFragmentManager(), mFragmentList, mTabList);
        vpHome.setAdapter(mAdapter);

        tablHome.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(TabLayout.Tab tab) {
                toolbar.setTitle(tab.getText());
            }

            @Override
            public void onTabUnselected(TabLayout.Tab tab) {
            }

            @Override
            public void onTabReselected(TabLayout.Tab tab) {
            }
        });

        tablHome.setupWithViewPager(vpHome);
    }

    @Override
    public void doBusiness() {

    }

    @Override
    public void onFragmentInteraction(Uri uri) {
        switch (uri.toString()) {
            case IntentTypeConstants.FRAGMENT_ARTICLE_BUTTOM1://文的按钮1
                showToast("111111111");
                startActivity(TestActivity.class);
                break;
        }
    }
}
